import { createBrowserRouter } from 'react-router'
import { lazy } from 'react'
import BasicLayout from '@/layout/BasicLayout'
import AuthGuard from '@/router/AuthGuard'

// 懒加载页面
// const Login   = lazy(() => import('@/pages/Login'))
const DeviceList  = lazy(() => import('@/pages/Device/List'))
const DeviceCreate= lazy(() => import('@/pages/Device/Create'))
const NotFound    = lazy(() => import('@/pages/NotFound'))

export const router = createBrowserRouter([
  {
    path: '/',
    element: <DeviceCreate />,
  },
  {
    element: <AuthGuard />,      // 鉴权外壳
    children: [
      {
        path: '/base',
        element: <BasicLayout />, // 布局外壳
        children: [
          { index: true, element: <DeviceList /> }, // 默认路由
          { path: 'device', element: <DeviceList /> },
          { path: 'device/create', element: <DeviceCreate /> },
        ],
      },
    ],
  },
  { path: '*', element: <NotFound /> },
])